/*
 * @Author: moxunjingmu
 * @Date: 2025-03-06 22:39:50
 * @Description: 
 */
const fs = require('fs');
const path = require('path');

module.exports = async (config) => {
  if (process.env.ARTIFACT_NAME && config.artifactPath) {
    const artifactDir = path.dirname(config.artifactPath);
    const artifactExt = path.extname(config.artifactPath);
    const newArtifactPath = path.join(artifactDir, `${process.env.ARTIFACT_NAME}${artifactExt}`);
    
    console.log(`重命名构建产物: ${config.artifactPath} -> ${newArtifactPath}`);
    
    try {
      fs.renameSync(config.artifactPath, newArtifactPath);
      config.artifactPath = newArtifactPath;
    } catch (e) {
      console.error('重命名文件失败:', e);
    }
  }
  return config;
};